package client.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.List;

import javax.swing.*;
import sharedspace.*;
/**
 * this class show computerized test checked to student
 * @author Amir
 *
 */
/**
 * This JFrame is a frame to show the test for student with his chooses and right answers.
 * @author Amir S.
 * @author Jacob C.
 * @author Maya G.
 * @author Michael V.
 *
 */

public class GUI_Student_ViewTest extends JFrame {
	private static final long serialVersionUID = 1L;
	private ApprovingGrade approvingGrade;
	private Toolkit toolkit = Toolkit.getDefaultToolkit();
	private Dimension scrnsize = toolkit.getScreenSize();
	private JLabel question = null;
	private JRadioButton answer = null;
	private JPanel form = null;
	private JScrollPane scroller = null;

	public GUI_Student_ViewTest(ApprovingGrade approvingGrade)
	{
		super();
		this.approvingGrade = approvingGrade;
		initalize();
	}
	/**
	 * Initialize screen
	 */
	public void initalize()
	{
		this.setSize(600, 800);
		this.setLocation((toolkit.getScreenSize().width-600)/2, (toolkit.getScreenSize().height-800)/2);
		this.setTitle("Test");
		this.setLayout(null);
		displayTest();
		this.add(scroller,null);
	}
	/**
	 * display test
	 */
	public void displayTest()
	{
		// making new JPanel for test
		
			form = new JPanel(new VerticalLayout(50,VerticalLayout.LEFT));
			form.setBackground(Color.WHITE);
			if (approvingGrade.getTeacherCommentForGrade()!=null && !approvingGrade.getTeacherCommentForGrade().equals("null"))
			{
				question = new JLabel("Reason for changing grade: "+approvingGrade.getTeacherCommentForGrade());
				question.setFont(new Font("Arial",Font.PLAIN,16));
				question.setForeground(Color.BLACK);
				form.add(question);
			}		
			for(int i = 0; i<approvingGrade.getStudentInTest().getChoises().size(); i++)
			{
				JPanel qPanel = new JPanel(new VerticalLayout(0, VerticalLayout.LEFT));
				qPanel.setBackground(Color.WHITE);
				question = new JLabel((i+1)+". "+approvingGrade.getStudentInTest().getChoises().get(i).getQuestion().getQuestion());
				question.setFont(new Font("Arial",Font.PLAIN,32));
				question.setForeground(Color.BLACK);
				ButtonGroup buttonGroup = new ButtonGroup();
				qPanel.add(question);// insert question to question JPanel
				question = new JLabel(" " + approvingGrade.getStudentInTest().getChoises().get(i).getQuestion().getQuestionCommet());
				qPanel.add(question);// insert questionComment to question JPanel
				int choice = approvingGrade.getStudentInTest().getChoises().get(i).getChoice();
				for (int j = 0; j<4; j++)
				{   //making JRadioButton for answers
					answer = new JRadioButton((j+1)+".     "+approvingGrade.getStudentInTest().getChoises().get(i).getQuestion().getAnswers()[j]);
					answer.setActionCommand(Integer.toString(i));
					answer.setBackground(null);
					if (j+1==choice)
						answer.setSelected(true);
					else answer.setEnabled(false);
					/*if choice incorrect answer will be red*/
					if (j+1==choice && choice!=approvingGrade.getStudentInTest().getChoises().get(i).getQuestion().getCorrectAnswer())
						answer.setBackground(Color.RED);
					/*correct answer will be yellow*/
					if (j+1==approvingGrade.getStudentInTest().getChoises().get(i).getQuestion().getCorrectAnswer())
						answer.setBackground(Color.YELLOW);
					qPanel.add(answer);
					buttonGroup.add(answer);
					
				}
				if (approvingGrade.getTeacherComment()[i]!=null && !approvingGrade.getTeacherComment()[i].equals("null"))
					question = new JLabel("Question "+(i+1)+" comment: "+approvingGrade.getTeacherComment()[i]);
				else 	question = new JLabel("Question "+(i+1)+" comment: unavailable");
				
				question.setBackground(null);
				qPanel.add(question);
				form.add(qPanel);
				
			}
			scroller= new JScrollPane(form);
			scroller.setBounds(new Rectangle(0, 0, 600, 780));
	}
	
	

}
